package com.cskaoyan.kpi.pv;

import com.cskaoyan.kpi.Summary;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @ClassName DailyPVReducer
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2022/1/19 9:39
 * @Version V1.0
 **/
public class DailyPVReducer extends Reducer<Text, IntWritable, Summary, Text> {

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable value : values) {
            sum += value.get();
        }
        //其实，reduce中我输出了三个数据 2021-01-14 dailyPV 1000000
        Summary dailyPV = new Summary(null, key.toString(), "dailyPV", sum + "", null);
        context.write(dailyPV, null);
    }
}
